package com.guanmi.ethereum.configure;

import com.guanmi.ethereum.service.BloggerCoin;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.http.HttpService;
import org.web3j.tx.ClientTransactionManager;
import org.web3j.tx.ManagedTransaction;
import org.web3j.tx.TransactionManager;

/**
 * 智能合約
 * @author zhulf
 */
@Configuration
public class ContractConfig {

    /**
     * 智能合约部署地址
     */
    private String contractAddress = "0x1F999F370c30Ddf49fFd795E5A65c392f1aA85a5";

    @Bean
    public BloggerCoin bloggerCoin() {
        Web3j web3j = Web3j.build(new HttpService("http://192.168.1.166:8545"));
        // 以某个用户的身份调用合约
        TransactionManager transactionManager = new ClientTransactionManager(web3j, "0xE78DC25d638195F4545287Fbe0d6A614a1eEe0F0");
        //加载智能合约
        return BloggerCoin.load(contractAddress, web3j, transactionManager, ManagedTransaction.GAS_PRICE, org.web3j.tx.Contract.GAS_LIMIT);
    }
}
